<template>
  <transition name="dialog-fade">
       <el-dialog 
       v-if="addotherDialog"
      title="添加内容"
      class="dialog-addother"
      :visible.sync="addotherDialog"
      width="800px"
      append-to-body
      @close="closeDialog(0)">
      <el-form
        ref="formInfo"
        :model="formInfo"
        class="demo-form-inline"
        :rules="rules"
        label-width="100px"
      >
        <el-form-item label="标题" prop="title">
          <el-input v-model="formInfo.title"></el-input>
        </el-form-item>
        <el-form-item style="text-align: right;">
          <el-button @click="addotherDialog=false">取消</el-button>
          <el-button type="primary" @click="submitForm('formInfo')">确定</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
  </transition>
</template>

<script>
import { otherAdd } from '@/api/user';
import Base64 from "@/utils/base"
// import { getuserid } from '../../utils/auth'
export default {
  name: "DialogAddseat",
  inject:["reload"],
  props: {
    // msg: {
    //   type: String,
    //   default: ''
    // },
    dialogaddTitle: {
      type: String,
      default: ""
    },
    itemInfo: {
      type: Object,
      default: function() {
        return {};
      }
    }
  },
  data() {
    return {
      rules: {
        title: [
          { required: true, message: "请输入标题", trigger: "change" }
        ],
      },
      addotherDialog: false,
      formInfo: {
        title:""
      },
      //   formInfo: JSON.parse(JSON.stringify(this.itemInfo))
    };
  },
  mounted() {
    // this.getOpt()
  },
  methods: {
    //   获取下拉框
    // getOpt() {
    //   this.getRequest('/asset/getTypeList', {}).then(res => {
    //     this.options = res.obj
    //   })
    // },
    // 保存操作
    submitForm(formName) {
      const that = this;
      that.$refs[formName].validate(valid => {
        if (valid) {
          let parmes = {
            title: that.formInfo.title,
            id: window.location.href.substr(window.location.href.length - 1, 1)
          };
          otherAdd({
            request_data: Base64.encode(JSON.stringify(parmes))
          }).then(res => {
             if(res.status==2){
          that.$message({
            message:res.message,
            type:'warning'
          })
          return
        }
             that.$message({
              message: res.message,
              type: "success"
            });
            that.closeDialog();
            that.reload()
          });
          // 走保存请求
        } else {
          return false;
        }
      });
    },
    // 关闭弹框
    closeDialog(flag) {
      this.$refs["formInfo"].resetFields();
      this.addotherDialog = false;
      this.$emit("closeDialog", flag);
    }
  }
};
</script>

<style scoped lang="scss">
.dialog-fade-enter-active {
  -webkit-animation: dialog-fade-in 0.3s;
  animation: dialog-fade-in 0.3s;
}
.dialog-fade-leave-active {
  -webkit-animation: dialog-fade-out 0.3s;
  animation: dialog-fade-out 0.3s;
}
@-webkit-keyframes dialog-fade-in {
  0% {
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    opacity: 0;
  }
  100% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}
@keyframes dialog-fade-in {
  0% {
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    opacity: 0;
  }
  100% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
}
@-webkit-keyframes dialog-fade-out {
  0% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
  100% {
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    opacity: 0;
  }
}
@keyframes dialog-fade-out {
  0% {
    -webkit-transform: translate3d(0, 0, 0);
    transform: translate3d(0, 0, 0);
    opacity: 1;
  }
  100% {
    -webkit-transform: translate3d(0, -20px, 0);
    transform: translate3d(0, -20px, 0);
    opacity: 0;
  }
}
</style>
